home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / database / postgres / mpsql-1.001 / mpsql-1~ / mpsql-1.0 / callback.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-29  |  38.5 KB  |  914 lines

  1. /************************************************************************/
  2. /* Module : callback.c                                    */
  3. /* Purpose: widget callback module for Mpsql                         */
  4. /* By     : Keith R. Davis                            */
  5. /* Date   : 12/8/95                                    */
  6. /* Notes  : Copyright(c) 1996 White River Software            */
  7. /************************************************************************/
  8.  
  9. #include <Xm/Xm.h>        /* motif lib header        */
  10. #include <Xm/PushB.h>        /* push button widget header    */
  11. #include <Xm/RowColumn.h>    /* row/col widget header    */
  12. #include <Xm/Label.h>        /* label widget header        */
  13. #include <Xm/List.h>            /* list widget header           */
  14. #include <Xm/TextF.h>        /* text widget header        */
  15. #include <Xm/MessageB.h>    /* message box header            */
  16. #include <Xm/FileSB.h>          /* file selection widget header */
  17. #include <string.h>        /* string lib header        */
  18. #include <stdio.h>              /* stdio header                 */
  19.  
  20. #include "pixmap.h"             /* pixmap header                */
  21. #include "mquel.h"              /* mquel header                 */
  22. #include "menu.h"        /* menu header                */
  23. #include "callback.h"           /* callback header              */
  24. #include "llist.h"              /* linked list header           */
  25. #include "db.h"                 /* db header                    */
  26. #include "util.h"               /* utility func. header         */
  27.  
  28. /************************************************************************/
  29. /* Function: DeleteWindowCallback                                       */
  30. /* Purpose : handles processing for WM_DELETE_WINDOW message            */
  31. /* Params  : standard callback stuff                                    */
  32. /* Returns : nothing                                                    */
  33. /* Notes   :                                                            */
  34. /************************************************************************/
  35.  
  36. void DeleteWindowCallback(Widget w, XtPointer clientdata, XtPointer callData)
  37. {
  38.   /* close database & remove linked list */ 
  39.   DB_Close();
  40.   LLIST_Remove();
  41.   exit(0);
  42. }
  43.  
  44. /************************************************************************/
  45. /* Function: ConnectCallback                                            */
  46. /* Purpose : handles database connection request                        */
  47. /* Params  : standard callback stuff                                    */
  48. /* Returns : nothing                                                    */
  49. /* Notes   :                                                            */
  50. /************************************************************************/
  51.  
  52. void ConnectCallback(Widget w, XtPointer clientdata, XtPointer callData)
  53. {
  54.   const char *title = "Connect";                   /* dialog title string            */
  55.   Widget rc;                                       /* rowcol widget for dialog       */
  56.   static Widget connect_dialog = NULL;             /* dialog widget                  */
  57.  
  58.   if(!connect_dialog){
  59.     connect_dialog = XmCreateMessageDialog(AppWidgetsPtr->mainwindow, "connectdialog", NULL, 0);
  60.   
  61.     /* remove uneeded children */
  62.     XtUnmanageChild(XmMessageBoxGetChild(connect_dialog, XmDIALOG_HELP_BUTTON));
  63.     XtUnmanageChild(XmMessageBoxGetChild(connect_dialog, XmDIALOG_SYMBOL_LABEL));
  64.     XtUnmanageChild(XmMessageBoxGetChild(connect_dialog, XmDIALOG_MESSAGE_LABEL));
  65.  
  66.     /* setup dialog */
  67.     XtVaSetValues(connect_dialog,
  68.           XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  69.           XtVaTypedArg, XmNdialogTitle, XmRString,
  70.           title, strlen(title)+1,
  71.           NULL);
  72.  
  73.     rc = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, connect_dialog,
  74.                  XmNnumColumns, 2,
  75.                  XmNpacking, XmPACK_COLUMN,
  76.                  XmNorientation, XmVERTICAL,
  77.                  NULL);
  78.  
  79.     XtCreateManagedWidget("Database name:", xmLabelWidgetClass, rc, NULL, 0);
  80.     XtCreateManagedWidget("Host name:", xmLabelWidgetClass, rc, NULL, 0);
  81.     XtCreateManagedWidget("Port:", xmLabelWidgetClass, rc, NULL, 0);
  82.  
  83.     AppWidgetsPtr->database = XtVaCreateManagedWidget("database", xmTextFieldWidgetClass,
  84.                               rc,
  85.                               XmNmaxLength, DB_NAME_SZ,
  86.                               NULL);
  87.     AppWidgetsPtr->host = XtVaCreateManagedWidget("host", xmTextFieldWidgetClass,
  88.                           rc, 
  89.                           XmNmaxLength, HOST_NAME_SZ,
  90.                           NULL);
  91.     AppWidgetsPtr->port = XtVaCreateManagedWidget("port", xmTextFieldWidgetClass,
  92.                         rc, 
  93.                         XmNmaxLength, PORT_NAME_SZ,
  94.                         NULL);
  95.     /* add callbacks */
  96.     XtAddCallback(connect_dialog, XmNokCallback, ConnectOKCallback, NULL);
  97.   }
  98.  
  99.   if(dbname != NULL)
  100.     XmTextSetString(AppWidgetsPtr->database, dbname);
  101.   if(host != NULL)
  102.     XmTextSetString(AppWidgetsPtr->host, host);
  103.   if(port != NULL)
  104.     XmTextSetString(AppWidgetsPtr->port, port);
  105.  
  106.   XtManageChild(connect_dialog);
  107. }
  108.  
  109. /************************************************************************/
  110. /* Function: ConnectOKCallback                                          */
  111. /* Purpose : calls DB_Connect()                                         */
  112. /* Params  : standard callback stuff                                    */
  113. /* Returns : nothing                                                    */
  114. /* Notes   :                                                            */
  115. /************************************************************************/
  116.  
  117. void ConnectOKCallback(Widget w, XtPointer clientData, XtPointer callData)
  118. {
  119.   strcpy(dbname, doubleTrim((char*)XmTextGetString(AppWidgetsPtr->database)));
  120.   strcpy(host, doubleTrim((char*)XmTextGetString(AppWidgetsPtr->host)));
  121.   strcpy(port, doubleTrim((char*)XmTextGetString(AppWidgetsPtr->port)));
  122.  
  123.   if((strlen(dbname) == 0) || (strlen(host) == 0) || (strlen(port) == 0))
  124.     ErrorMsg("Connect", "Make sure all fields are filled!");
  125.   else
  126.     DB_Connect();
  127. }
  128.  
  129. /************************************************************************/
  130. /* Function: NewCallback                                                */
  131. /* Purpose : handles new buffer request                                 */
  132. /* Params  : standard callback stuff                                    */
  133. /* Returns : nothing                                                    */
  134. /* Notes   :                                                            */
  135. /************************************************************************/
  136.  
  137. void NewCallback(Widget w, XtPointer clientdata, XtPointer callData)
  138. {
  139.   if((buffer_curr = DB_OpenScratchBuffer()) != NULL)
  140.     buffer_curr = DB_SetBuffer(buffer_curr);
  141. }
  142.  
  143. /************************************************************************/
  144. /* Function: OpenCallback                                               */
  145. /* Purpose : handles open file request                                  */
  146. /* Params  : standard callback stuff                                    */
  147. /* Returns : nothing                                                    */
  148. /* Notes   :                                                            */
  149. /************************************************************************/
  150.  
  151. void OpenCallback(Widget w, XtPointer clientdata, XtPointer callData)
  152. {
  153.   const char *title = "Open";           /* dialog title string          */     
  154.   Widget text = (Widget)clientdata;     /* selected file info           */
  155.   static Widget open_dialog = NULL;     /* dialog widget                */
  156.  
  157.   if(!open_dialog){
  158.     open_dialog = XmCreateFileSelectionDialog(AppWidgetsPtr->mainwindow,
  159.                           "OpenFileDialog",
  160.                           NULL, 0);
  161.     /* setup dialog */
  162.     XtVaSetValues(open_dialog,
  163.           XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  164.           XtVaTypedArg, XmNdialogTitle, XmRString,
  165.           title, strlen(title)+1,
  166.           NULL);
  167.  
  168.     /* add callbacks */
  169.     XtAddCallback(open_dialog, XmNokCallback, OpenOKCallback, NULL);
  170.     XtAddCallback(open_dialog, XmNcancelCallback, OpenCancelCallback, NULL);
  171.   }
  172.   XtManageChild(open_dialog);
  173. }
  174.  
  175. /************************************************************************/
  176. /* Function: OpenOKCallback                                             */
  177. /* Purpose : calls DB_OpenFile()                                        */
  178. /* Params  : standard callback stuff                                    */
  179. /* Returns : nothing                                                    */
  180. /* Notes   : file errors handled by DB_OpenFile()                       */
  181. /************************************************************************/
  182.  
  183. void OpenOKCallback(Widget w, XtPointer clientdata, XtPointer callData)
  184. {
  185.   char *filename;         /* file to open               */
  186.  
  187.   /* get the filename selected */
  188.   XmFileSelectionBoxCallbackStruct *cbs =
  189.     (XmFileSelectionBoxCallbackStruct*)callData;
  190.  
  191.   XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &filename);
  192.  
  193.   /* close dialog */
  194.   XtUnmanageChild(w);
  195.  
  196.   /* open the file */
  197.   DB_OpenFile(filename);
  198. }
  199.  
  200. /************************************************************************/
  201. /* Function: OpenCancelCallback                                         */
  202. /* Purpose : closes open file dialog on cancel                          */
  203. /* Params  : standard callback stuff                                    */
  204. /* Returns : nothing                                                    */
  205. /* Notes   :                                                            */
  206. /************************************************************************/
  207.  
  208. void OpenCancelCallback(Widget w, XtPointer clientdata, XtPointer callData)
  209. {
  210.   XtUnmanageChild(w);
  211. }
  212.  
  213. /************************************************************************/
  214. /* Function: SaveCallback                                               */
  215. /* Purpose : handles save file request                                  */
  216. /* Params  : standard callback stuff                                    */
  217. /* Returns : nothing                                                    */
  218. /* Notes   : file errors handled by DB_SaveFile()                       */
  219. /************************************************************************/
  220.  
  221. void SaveCallback(Widget w, XtPointer clientdata, XtPointer callData)
  222. {
  223.   if(strcmp(buffer_curr->filename, "scratch") == 0)
  224.     SaveAsCallback(NULL, NULL, NULL);
  225.   else
  226.     DB_SaveFile(buffer_curr);
  227. }
  228.  
  229. /************************************************************************/
  230. /* Function: SaveAsCallback                                             */
  231. /* Purpose : handles save as file request                               */
  232. /* Params  : standard callback stuff                                    */
  233. /* Returns : nothing                                                    */
  234. /* Notes   :                                                            */
  235. /************************************************************************/
  236.  
  237. void SaveAsCallback(Widget w, XtPointer clientdata, XtPointer callData)
  238. {
  239.   const char *title = "Save As";          /* dialog title string        */
  240.   Widget text = (Widget)clientdata;       /* selected file data         */
  241.   static Widget save_dialog = NULL;       /* dialog widget              */
  242.  
  243.   if(!save_dialog){
  244.     save_dialog = XmCreateFileSelectionDialog(AppWidgetsPtr->mainwindow,
  245.                           "SaveFileDialog",
  246.                           NULL, 0);
  247.  
  248.     /* setup dialog */
  249.     XtVaSetValues(save_dialog,
  250.           XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  251.           XtVaTypedArg, XmNdialogTitle, XmRString,
  252.           title, strlen(title)+1,
  253.           NULL);
  254.  
  255.     /* add callbacks */
  256.     XtAddCallback(save_dialog, XmNokCallback, SaveAsOKCallback, NULL);
  257.     XtAddCallback(save_dialog, XmNcancelCallback, SaveAsCancelCallback, NULL);
  258.   }
  259.   XtManageChild(save_dialog);
  260. }
  261.  
  262. /************************************************************************/
  263. /* Function: SaveAsOKCallback                                           */
  264. /* Purpose : calls DB_SaveFile()                                        */
  265. /* Params  : standard callback stuff                                    */
  266. /* Returns : nothing                                                    */
  267. /* Notes   : file errors handled by DB_SaveFile()                       */
  268. /************************************************************************/
  269.  
  270. void SaveAsOKCallback(Widget w, XtPointer clientdata, XtPointer callData)
  271. {
  272.   char *filename;            /* filename to save as                     */
  273.   char tmp_fn[MAX_PATH_LEN]; /* tmp filename                            */
  274.  
  275.   /* get filename */
  276.   XmFileSelectionBoxCallbackStruct *cbs =
  277.     (XmFileSelectionBoxCallbackStruct*)callData;
  278.  
  279.   XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &filename);
  280.  
  281.   XtUnmanageChild(w);
  282.  
  283.   /* save the file & copy new filename to linked list node holding the buffered file data */
  284.   strcpy(tmp_fn, buffer_curr->filename);
  285.   strcpy(buffer_curr->filename, filename);
  286.  
  287.   if(!DB_SaveFile(buffer_curr))
  288.     strcpy(buffer_curr->filename, tmp_fn);
  289. }
  290.  
  291. /************************************************************************/
  292. /* Function: SaveAsCancelCallback                                       */
  293. /* Purpose : closes save as file dialog on cancel                       */
  294. /* Params  : standard callback stuff                                    */
  295. /* Returns : nothing                                                    */
  296. /* Notes   :                                                            */
  297. /************************************************************************/
  298.  
  299. void SaveAsCancelCallback(Widget w, XtPointer clientdata, XtPointer callData)
  300. {
  301.   XtUnmanageChild(w);
  302. }
  303.  
  304. /************************************************************************/
  305. /* Function: CloseCallback                                              */
  306. /* Purpose : handles exit application request                           */
  307. /* Params  : standard callback stuff                                    */
  308. /* Returns : nothing                                                    */
  309. /* Notes   :                                                            */
  310. /************************************************************************/
  311.  
  312. void CloseCallback(Widget w, XtPointer clientdata, XtPointer callData)
  313. {
  314.   /* dialog message strings */
  315.   const char *title = "Quit";
  316.   const char *quit_msg = "Unsaved modified buffers exist.\nContinue without saving?";
  317.   
  318.   /* dialog widget */
  319.   static Widget close_dialog = NULL;
  320.  
  321.   /* check linked list for modified buffers & if so, prompt user ...*/
  322.   if(DB_ChkModBuffers()){
  323.  
  324.     if(!close_dialog){
  325.       close_dialog = XmCreateQuestionDialog(AppWidgetsPtr->mainwindow, "closedialog", NULL, 0);
  326.     
  327.       /* remove uneeded children */
  328.       XtUnmanageChild(XmMessageBoxGetChild(close_dialog, XmDIALOG_HELP_BUTTON));
  329.     
  330.       /* setup dialog */
  331.       XtVaSetValues(close_dialog,
  332.             XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  333.             XtVaTypedArg, XmNdialogTitle, XmRString,
  334.             title, strlen(title)+1,
  335.             XtVaTypedArg, XmNmessageString, XmRString,
  336.             quit_msg, strlen(quit_msg)+1, NULL);
  337.     
  338.       /* add callbacks */
  339.       XtAddCallback(close_dialog, XmNokCallback, ReallyQuitCallback, NULL);
  340.     }
  341.     XtManageChild(close_dialog);
  342.   }
  343.   else {
  344.     /* shutdown application */
  345.     DB_Close();
  346.     LLIST_Remove();
  347.     exit(0);
  348.   }
  349. }
  350.  
  351. /************************************************************************/
  352. /* Function: ReallyQuitCallback                                         */
  353. /* Purpose : handles exit application request                           */
  354. /* Params  : standard callback stuff                                    */
  355. /* Returns : nothing                                                    */
  356. /* Notes   : if the app has modified buffers on close, this will force  */
  357. /*           closing with out saving...(OK button)                      */
  358. /************************************************************************/
  359.  
  360. void ReallyQuitCallback(Widget w, XtPointer clientData, XtPointer callData)
  361. {
  362.     DB_Close();
  363.     LLIST_Remove();
  364.     exit(0);
  365. }
  366.  
  367. /************************************************************************/
  368. /* Function: CutCallback                                                */
  369. /* Purpose : handles cuting of selected text to clipboard               */
  370. /* Params  : standard callback stuff                                    */
  371. /* Returns : nothing                                                    */
  372. /* Notes   :                                                            */
  373. /************************************************************************/
  374.  
  375. void CutCallback(Widget w, XtPointer clientdata, XtPointer callData)
  376. {
  377.   XmTextCut(AppWidgetsPtr->sqlwindow, XtLastTimestampProcessed(XtDisplay(w)));
  378. }
  379.  
  380. /************************************************************************/
  381. /* Function: CopyCallback                                               */
  382. /* Purpose : handles copying of selected text to clipboard              */
  383. /* Params  : standard callback stuff                                    */
  384. /* Returns : nothing                                                    */
  385. /* Notes   :                                                            */
  386. /************************************************************************/
  387.  
  388. void CopyCallback(Widget w, XtPointer clientdata, XtPointer callData)
  389.   if((char*)XmTextGetSelection(AppWidgetsPtr->sqlwindow) != NULL)
  390.     XmTextCopy(AppWidgetsPtr->sqlwindow, XtLastTimestampProcessed(XtDisplay(w)));
  391.   else if((char*)XmTextGetSelection(AppWidgetsPtr->resultwindow) != NULL)
  392.     XmTextCopy(AppWidgetsPtr->resultwindow, XtLastTimestampProcessed(XtDisplay(w)));
  393. }
  394.  
  395. /************************************************************************/
  396. /* Function: PasteCallback                                              */
  397. /* Purpose : handles pasting of text from the clipboard                 */
  398. /* Params  : standard callback stuff                                    */
  399. /* Returns : nothing                                                    */
  400. /* Notes   :                                                            */
  401. /************************************************************************/
  402.  
  403. void PasteCallback(Widget w, XtPointer clientdata, XtPointer callData)
  404. {
  405.   XmTextPaste(AppWidgetsPtr->sqlwindow);
  406. }
  407.  
  408. /************************************************************************/
  409. /* Function: ClearResultCallback                                        */
  410. /* Purpose : clears the result window                                   */
  411. /* Params  : standard callback stuff                                    */
  412. /* Returns : nothing                                                    */
  413. /* Notes   :                                                            */
  414. /************************************************************************/
  415.  
  416. void ClearResultCallback(Widget w, XtPointer clientdata, XtPointer callData)
  417. {
  418.   XmTextSetString(AppWidgetsPtr->resultwindow, '\0');
  419. }
  420.  
  421. /************************************************************************/
  422. /* Function: SpoolCallback                                              */
  423. /* Purpose : handles spool file definition                              */
  424. /* Params  : standard callback stuff                                    */
  425. /* Returns : nothing                                                    */
  426. /* Notes   :                                                            */
  427. /************************************************************************/
  428.  
  429. void SpoolCallback(Widget w, XtPointer clientdata, XtPointer callData)
  430. {
  431.   const char *title = "Spool";                   /* dialog title        */
  432.   Widget rc;                                     /* rowcol widget       */
  433.   static Widget spool_dialog = NULL;             /* dialog widget       */
  434.  
  435.   if(!spool_dialog){
  436.     spool_dialog = XmCreateMessageDialog(AppWidgetsPtr->mainwindow, "spooldialog", NULL, 0);
  437.   
  438.     /* remove uneeded children */
  439.     XtUnmanageChild(XmMessageBoxGetChild(spool_dialog, XmDIALOG_HELP_BUTTON));
  440.     XtUnmanageChild(XmMessageBoxGetChild(spool_dialog, XmDIALOG_SYMBOL_LABEL));
  441.     XtUnmanageChild(XmMessageBoxGetChild(spool_dialog, XmDIALOG_MESSAGE_LABEL));
  442.  
  443.     /* setup dialog */
  444.     XtVaSetValues(spool_dialog,
  445.           XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  446.           XtVaTypedArg, XmNdialogTitle, XmRString,
  447.           title, strlen(title)+1,
  448.           NULL);
  449.  
  450.     rc = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, spool_dialog,
  451.                  XmNnumColumns, 2,
  452.                  XmNpacking, XmPACK_COLUMN,
  453.                  XmNorientation, XmVERTICAL,
  454.                  NULL);
  455.  
  456.     XtCreateManagedWidget("Enter spool filename:", xmLabelWidgetClass, rc, NULL, 0);
  457.     AppWidgetsPtr->spoolfile = XtVaCreateManagedWidget("spoolfile", xmTextFieldWidgetClass,
  458.                                rc,
  459.                                XmNmaxLength, MAX_PATH_LEN,
  460.                                NULL);
  461.  
  462.     /* add callback */
  463.     XtAddCallback(spool_dialog, XmNokCallback, SpoolOKCallback, NULL);
  464.   }
  465.  
  466.   if(spool_file != NULL)
  467.     XmTextSetString(AppWidgetsPtr->spoolfile, spool_file);
  468.  
  469.   XtManageChild(spool_dialog);
  470. }
  471.  
  472. /************************************************************************/
  473. /* Function: SpoolOKCallback                                            */
  474. /* Purpose : sets spool file name to user definition                    */
  475. /* Params  : standard callback stuff                                    */
  476. /* Returns : nothing                                                    */
  477. /* Notes   :                                                            */
  478. /************************************************************************/
  479.  
  480. void SpoolOKCallback(Widget w, XtPointer clientdata, XtPointer callData)
  481. {
  482.   strcpy(spool_file, doubleTrim((char *)XmTextGetString(AppWidgetsPtr->spoolfile)));  
  483. }
  484.  
  485. /************************************************************************/
  486. /* Function: ColWidthCallback                                           */
  487. /* Purpose : handles column width definition                            */
  488. /* Params  : standard callback stuff                                    */
  489. /* Returns : nothing                                                    */
  490. /* Notes   :                                                            */
  491. /************************************************************************/
  492.  
  493. void ColWidthCallback(Widget w, XtPointer clientdata, XtPointer callData)
  494. {
  495.   const char *title = "Column Width";          /* dialog title          */
  496.   Widget rc;                                   /* rowcol widget         */
  497.   static Widget colwidth_dialog = NULL;        /* dialog widget         */
  498.   char num_value[5];                           /* col width value       */
  499.  
  500.   if(!colwidth_dialog){
  501.     colwidth_dialog = XmCreateMessageDialog(AppWidgetsPtr->mainwindow, 
  502.                         "colwidthdialog", NULL, 0);
  503.   
  504.     /* remove uneeded children */
  505.     XtUnmanageChild(XmMessageBoxGetChild(colwidth_dialog, XmDIALOG_HELP_BUTTON));
  506.     XtUnmanageChild(XmMessageBoxGetChild(colwidth_dialog, XmDIALOG_SYMBOL_LABEL));
  507.     XtUnmanageChild(XmMessageBoxGetChild(colwidth_dialog, XmDIALOG_MESSAGE_LABEL));
  508.  
  509.     /* setup dialog */
  510.     XtVaSetValues(colwidth_dialog,
  511.           XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  512.           XtVaTypedArg, XmNdialogTitle, XmRString,
  513.           title, strlen(title)+1,
  514.           NULL);
  515.  
  516.     rc = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, colwidth_dialog,
  517.                  XmNnumColumns, 2,
  518.                  XmNpacking, XmPACK_COLUMN,
  519.                  XmNorientation, XmVERTICAL,
  520.                  NULL);
  521.  
  522.     XtCreateManagedWidget("Enter column width:", xmLabelWidgetClass, rc, NULL, 0);
  523.     AppWidgetsPtr->colwidth = XtVaCreateManagedWidget("colwidth", xmTextFieldWidgetClass,
  524.                               rc,
  525.                               XmNmaxLength, COL_SZ,
  526.                               NULL);
  527.  
  528.     /* add callbacks */
  529.     XtAddCallback(colwidth_dialog, XmNokCallback, ColWidthOKCallback, NULL);
  530.   }
  531.  
  532.   XmTextSetString(AppWidgetsPtr->colwidth, itoa(col_width, num_value));
  533.  
  534.   XtManageChild(colwidth_dialog);
  535. }
  536.  
  537. /************************************************************************/
  538. /* Function: ColWidthCallback                                           */
  539. /* Purpose : set column width to user definition                        */
  540. /* Params  : standard callback stuff                                    */
  541. /* Returns : nothing                                                    */
  542. /* Notes   :                                                            */
  543. /************************************************************************/
  544.  
  545. void ColWidthOKCallback(Widget w, XtPointer clientdata, XtPointer callData)
  546. {
  547.   col_width = atoi(doubleTrim((char *)XmTextGetString(AppWidgetsPtr->colwidth)));
  548. }
  549.  
  550. /************************************************************************/
  551. /* Function: SaveOptCallback                                            */
  552. /* Purpose : saves user defined options                                 */
  553. /* Params  : standard callback stuff                                    */
  554. /* Returns : nothing                                                    */
  555. /* Notes   :                                                            */
  556. /************************************************************************/
  557.  
  558. void SaveOptCallback(Widget w, XtPointer clientdata, XtPointer callData)
  559. {
  560.   MQUEL_SaveOptions();
  561. }
  562.  
  563. /************************************************************************/
  564. /* Function: AboutCallback                                              */
  565. /* Purpose : displays the about box                                     */
  566. /* Params  : standard callback stuff                                    */
  567. /* Returns : nothing                                                    */
  568. /* Notes   :                                                            */
  569. /************************************************************************/
  570.  
  571. void AboutCallback(Widget w, XtPointer clientdata, XtPointer callData)
  572. {
  573.   /* dialog message strings */
  574.   const char *title = "About";
  575.   const char *info = "MPSQL\nv1.0.0\n\nBy Keith R. Davis\nEmail: (keidav@accessone.com)\n\nCopyright (c) 1996 White River Software";
  576.   Widget rc, picture;
  577.   static Widget about_dialog = NULL;
  578.  
  579.   if(!about_dialog){
  580.     about_dialog = XmCreateMessageDialog(AppWidgetsPtr->mainwindow, "aboutdialog", NULL, 0);
  581.   
  582.     /* remove uneeded children */
  583.     XtUnmanageChild(XmMessageBoxGetChild(about_dialog, XmDIALOG_HELP_BUTTON));
  584.     XtUnmanageChild(XmMessageBoxGetChild(about_dialog, XmDIALOG_CANCEL_BUTTON));
  585.     XtUnmanageChild(XmMessageBoxGetChild(about_dialog, XmDIALOG_SYMBOL_LABEL));
  586.     XtUnmanageChild(XmMessageBoxGetChild(about_dialog, XmDIALOG_MESSAGE_LABEL));
  587.  
  588.     /* setup dialog */
  589.     XtVaSetValues(about_dialog,
  590.           XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  591.           XtVaTypedArg, XmNdialogTitle, XmRString,
  592.           title, strlen(title)+1,
  593.           NULL);
  594.  
  595.     rc = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, about_dialog,
  596.                  XmNnumColumns, 2,
  597.                  XmNpacking, XmPACK_TIGHT,
  598.                  XmNorientation, XmHORIZONTAL,
  599.                  NULL);
  600.  
  601.     picture =  XtVaCreateManagedWidget("", 
  602.                        xmLabelWidgetClass, rc,
  603.                        XmNmarginWidth, 15,
  604.                        XmNmarginHeight, 20,
  605.                        XmNalignment, XmALIGNMENT_CENTER,
  606.                        NULL);
  607.  
  608.     /* set label image */
  609.     InstallLabeledPixmap(picture, about_xpm);
  610.  
  611.     XtVaCreateManagedWidget("info", 
  612.                 xmLabelWidgetClass, rc,
  613.                 XtVaTypedArg, XmNlabelString, XmRString,
  614.                 info, strlen(info)+1,
  615.                 XmNalignment, XmALIGNMENT_CENTER,
  616.                 NULL);
  617.   }
  618.   XtManageChild(about_dialog);
  619. }
  620.  
  621. /************************************************************************/
  622. /* Function: PrintCallback                                              */
  623. /* Purpose : handles printer definition & submits print job             */
  624. /* Params  : standard callback stuff                                    */
  625. /* Returns : nothing                                                    */
  626. /* Notes   :                                                            */
  627. /************************************************************************/
  628.  
  629. void PrintCallback(Widget w, XtPointer clientdata, XtPointer callData)
  630. {
  631.   const char *title = "Print";               /* dialog title            */
  632.   Widget rc;                                 /* rowcol widget           */
  633.   static Widget print_dialog = NULL;         /* dialog widget           */
  634.  
  635.   if(!print_dialog){
  636.     print_dialog = XmCreateMessageDialog(AppWidgetsPtr->mainwindow, "printdialog", NULL, 0);
  637.   
  638.     /* remove uneeded children */
  639.     XtUnmanageChild(XmMessageBoxGetChild(print_dialog, XmDIALOG_HELP_BUTTON));
  640.     XtUnmanageChild(XmMessageBoxGetChild(print_dialog, XmDIALOG_SYMBOL_LABEL));
  641.     XtUnmanageChild(XmMessageBoxGetChild(print_dialog, XmDIALOG_MESSAGE_LABEL));
  642.  
  643.     /* setup dialog */
  644.     XtVaSetValues(print_dialog,
  645.           XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  646.           XtVaTypedArg, XmNdialogTitle, XmRString,
  647.           title, strlen(title)+1,
  648.           NULL);
  649.  
  650.     rc = XtVaCreateManagedWidget("rc", xmRowColumnWidgetClass, print_dialog,
  651.                  XmNnumColumns, 2,
  652.                  XmNpacking, XmPACK_COLUMN,
  653.                  XmNorientation, XmVERTICAL,
  654.                  NULL);
  655.  
  656.     XtCreateManagedWidget("Enter target printer:", xmLabelWidgetClass, rc, NULL, 0);
  657.     AppWidgetsPtr->printer = XtVaCreateManagedWidget("printer", xmTextFieldWidgetClass,
  658.                              rc,
  659.                              XmNmaxLength, PRINT_NAME_SZ,
  660.                              NULL);
  661.  
  662.     /* add callback */
  663.     XtAddCallback(print_dialog, XmNokCallback, PrintOKCallback, NULL);
  664.   }
  665.  
  666.   if(printer != NULL)
  667.     XmTextSetString(AppWidgetsPtr->printer, printer);
  668.  
  669.   XtManageChild(print_dialog);
  670. }
  671.  
  672. /************************************************************************/
  673. /* Function: PrintOKCallback                                            */
  674. /* Purpose : calls DB_PrintBuffer()                                     */
  675. /* Params  : standard callback stuff                                    */
  676. /* Returns : nothing                                                    */
  677. /* Notes   :                                                            */
  678. /************************************************************************/
  679.  
  680. void PrintOKCallback(Widget w, XtPointer clientdata, XtPointer callData)
  681. {
  682.   strcpy(printer, doubleTrim((char*)XmTextGetString(AppWidgetsPtr->printer)));
  683.   if(strlen(printer) == 0)
  684.     ErrorMsg("Print", "You must specify a printer!");
  685.   DB_PrintBuffer(buffer_curr, printer);
  686. }
  687.  
  688. /************************************************************************/
  689. /* Function: ExecSQLCallback                                            */
  690. /* Purpose : calls DB_SubmitQy()                                        */
  691. /* Params  : standard callback stuff                                    */
  692. /* Returns : nothing                                                    */
  693. /* Notes   :                                                            */
  694. /************************************************************************/
  695.  
  696. void ExecSQLCallback(Widget w, XtPointer clientdata, XtPointer callData)
  697. {
  698.   DB_SubmitQy();
  699. }
  700.  
  701. /************************************************************************/
  702. /* Function: CascadeCallback                                            */
  703. /* Purpose : creates a menu of open buffers to select.                  */
  704. /* Params  : standard callback stuff                                    */
  705. /* Returns : nothing                                                    */
  706. /* Notes   :                                                            */
  707. /************************************************************************/
  708.  
  709. void CascadeCallback(Widget w, XtPointer clientdata, XtPointer callData)
  710. {
  711.   int i;
  712.   static Widget btn[255];
  713.   static int list_cnt = 0;
  714.   LLISTbuffer *curr;    
  715.   char tmp[4];
  716.  
  717.   for(i = 0; i < list_cnt; i++)
  718.     XtUnrealizeWidget(btn[i]);
  719.  
  720.   for(i = 0; i < list_cnt; i++)
  721.     XtDestroyWidget(btn[i]);
  722.  
  723.   list_cnt = LLIST_Count();
  724.  
  725.   for(i = 0; i < list_cnt; i++){
  726.     curr = LLIST_Get(i+1);
  727.     btn[i] = XtVaCreateManagedWidget(itoa(i, tmp),
  728.                      xmPushButtonWidgetClass,
  729.                      AppWidgetsPtr->buffermenu,
  730.                      XtVaTypedArg, XmNlabelString, XmRString,
  731.                      curr->filename, strlen(curr->filename)+1,
  732.                      NULL);
  733.     XtAddCallback(btn[i], XmNactivateCallback, BufferCallback, NULL);
  734.   }
  735. }
  736.  
  737. /************************************************************************/
  738. /* Function: BufferCallback                                             */
  739. /* Purpose : sets the SQL window to the selected buffer                 */
  740. /* Params  : standard callback stuff                                    */
  741. /* Returns : nothing                                                    */
  742. /* Notes   :                                                            */
  743. /************************************************************************/
  744.  
  745. void BufferCallback(Widget w, XtPointer clientdata, XtPointer callData)
  746. {
  747.   LLISTbuffer *curr;
  748.  
  749.   curr = LLIST_Get(atoi(XtName(w)) + 1);
  750.   buffer_curr = DB_SetBuffer(curr);
  751. }
  752.  
  753. /************************************************************************/
  754. /* Function: TextModifiedCallback                                       */
  755. /* Purpose : flags a buffer as modified if text changes                 */
  756. /* Params  : standard callback stuff                                    */
  757. /* Returns : nothing                                                    */
  758. /* Notes   :                                                            */
  759. /************************************************************************/
  760.  
  761. void TextModifiedCallback(Widget w, XtPointer clientdata, XtPointer callData)
  762. {
  763.   buffer_curr->modified = 1;
  764. }
  765.  
  766. /************************************************************************/
  767. /* Function: DeleteBufferCallback                                       */
  768. /* Purpose : handles user request to delete the current buffer          */
  769. /* Params  : standard callback stuff                                    */
  770. /* Returns : nothing                                                    */
  771. /* Notes   :                                                            */
  772. /************************************************************************/
  773.  
  774. void DeleteBufferCallback(Widget w, XtPointer clientdata, XtPointer callData)
  775. {
  776.   /* dial title strings */
  777.   const char *title = "Delete Buffer";
  778.   const char *del_msg = "Buffer has been modified,\ndelete without saving changes?";
  779.   static Widget del_dialog = NULL;
  780.  
  781.   /* if the buffer is modified prompt the user to continue delete */
  782.   if(buffer_curr->modified == 1){
  783.     if(!del_dialog){
  784.       del_dialog = XmCreateQuestionDialog(AppWidgetsPtr->mainwindow, "deldialog", NULL, 0);
  785.     
  786.       /* remove uneeded children */
  787.       XtUnmanageChild(XmMessageBoxGetChild(del_dialog, XmDIALOG_HELP_BUTTON));
  788.     
  789.       /* setup dialog */
  790.       XtVaSetValues(del_dialog,
  791.             XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  792.             XtVaTypedArg, XmNdialogTitle, XmRString,
  793.             title, strlen(title)+1,
  794.             XtVaTypedArg, XmNmessageString, XmRString,
  795.             del_msg, strlen(del_msg)+1, NULL);
  796.     
  797.       /* add callback */
  798.       XtAddCallback(del_dialog, XmNokCallback, DeleteBufferOKCallback, NULL);
  799.     }
  800.     
  801.     XtManageChild(del_dialog);
  802.   }
  803.   else
  804.     DB_DeleteBuffer(buffer_curr);
  805. }
  806.  
  807. /************************************************************************/
  808. /* Function: DeleteBufferOKCallback                                     */
  809. /* Purpose : deletes the current buffer on user confirmation            */
  810. /* Params  : standard callback stuff                                    */
  811. /* Returns : nothing                                                    */
  812. /* Notes   :                                                            */
  813. /************************************************************************/
  814.  
  815. void DeleteBufferOKCallback(Widget w, XtPointer clientdata, XtPointer callData)
  816. {
  817.   DB_DeleteBuffer(buffer_curr);
  818. }
  819.  
  820. /************************************************************************/
  821. /* Function: ErrorMsg                                                   */
  822. /* Purpose : displays a basic message box with an error string          */
  823. /* Params  : title : dialog title                                       */
  824. /*           msg : dialog box message string                            */
  825. /* Returns : nothing                                                    */
  826. /* Notes   :                                                            */
  827. /************************************************************************/
  828.  
  829. void ErrorMsg(char *title, char *msg)
  830.   /* dialog widget */
  831.   static Widget error_dialog = NULL;
  832.  
  833.   if(!error_dialog){
  834.     error_dialog = XmCreateErrorDialog(AppWidgetsPtr->mainwindow, "errordialog", NULL, 0);
  835.     
  836.     /* remove uneeded children */
  837.     XtUnmanageChild(XmMessageBoxGetChild(error_dialog, XmDIALOG_HELP_BUTTON));
  838.     XtUnmanageChild(XmMessageBoxGetChild(error_dialog, XmDIALOG_CANCEL_BUTTON));
  839.  
  840.   }
  841.   /* setup dialog */
  842.   XtVaSetValues(error_dialog,
  843.         XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  844.         XtVaTypedArg, XmNdialogTitle, XmRString,
  845.         title, strlen(title)+1,
  846.         XtVaTypedArg, XmNmessageString, XmRString,
  847.         msg, strlen(msg)+1, NULL);
  848.  
  849.   XtManageChild(error_dialog);
  850. }
  851.  
  852. /************************************************************************/
  853. /* Function: GetColSeparator                                            */
  854. /* Purpose : returns the column separator character                     */
  855. /* Params  :                                                            */
  856. /* Returns : char to set                                                */
  857. /* Notes   :                                                            */
  858. /************************************************************************/
  859.  
  860. char GetColSeparator(void)
  861. {
  862.   if(XmToggleButtonGetState(AppWidgetsPtr->none))
  863.     return '\0';
  864.   else if(XmToggleButtonGetState(AppWidgetsPtr->tab))
  865.     return '\t';
  866.   else if(XmToggleButtonGetState(AppWidgetsPtr->space))
  867.     return ' ';
  868.   else if(XmToggleButtonGetState(AppWidgetsPtr->comma))
  869.     return ',';
  870. }
  871.  
  872. /************************************************************************/
  873. /* Function: GetColSeparatorId                                          */
  874. /* Purpose : returns the column separator character const               */
  875. /* Params  :                                                            */
  876. /* Returns : 0: NONE, 1: TAB, 2: SPACE, 3: COMMA                        */
  877. /* Notes   :                                                            */
  878. /************************************************************************/
  879.  
  880. int GetColSeparatorId(void)
  881. {
  882.   if(XmToggleButtonGetState(AppWidgetsPtr->none))
  883.     return NONE;
  884.   else if(XmToggleButtonGetState(AppWidgetsPtr->tab))
  885.     return TAB;
  886.   else if(XmToggleButtonGetState(AppWidgetsPtr->space))
  887.     return SPACE;
  888.   else if(XmToggleButtonGetState(AppWidgetsPtr->comma))
  889.     return COMMA;
  890. }
  891.  
  892. /************************************************************************/
  893. /* Function: SetColSeparator                                            */
  894. /* Purpose : handles setting column separator character                 */
  895. /* Params  : sep_value : int represent char to set                      */
  896. /*           0: NONE, 1: TAB, 2: SPACE, 3: COMMA                        */
  897. /* Returns :                                                            */
  898. /* Notes   :                                                            */
  899. /************************************************************************/
  900.  
  901. void SetColSeparator(int sep_value)
  902. {
  903.   if(sep_value == NONE)
  904.     XmToggleButtonSetState(AppWidgetsPtr->none, 1, TRUE);
  905.   else if(sep_value == TAB)
  906.     XmToggleButtonSetState(AppWidgetsPtr->tab, 1, TRUE);
  907.   else if(sep_value == SPACE)
  908.     XmToggleButtonSetState(AppWidgetsPtr->space, 1, TRUE);
  909.   else if(sep_value == COMMA)
  910.     XmToggleButtonSetState(AppWidgetsPtr->comma, 1, TRUE);
  911. }
  912.